import tkinter as tk
#2021-04-24 00:08
#修改自官方的3.7.10的Library Reference P1313
class Application(tk.Frame):#即Application类继承自tk.Frame
    count=0
    def __init__(self,master=None):#即class初始化
        super().__init__(master)
        self.master=master
        self.pack()
        self.create_widgets()
        
    def create_widgets(self):
        self.hi_there=tk.Button(self)
        self.hi_there["text"]=f"Hello World {self.count}\n(click me)"
        self.hi_there["command"]=self.say_hi
        self.hi_there.pack(side="top")

        self.quit=tk.Button(self,text="QUIT",fg="red",command=self.master.destroy)
        self.quit.pack(side="bottom")

    def say_hi(self):
        self.count+=1
        print(f"hi there,everyone! {self.count}")#将会在控制台输出hi there,everyone!
        self.hi_there["text"]=f"Hello World {self.count}\n(click me)"

root=tk.Tk()#创建顶级Tk窗口
app=Application(master=root)
app.mainloop()
